package com.dingding.order.core.servicemod.biz.impl;

import java.util.ArrayList;
import java.util.List;
import javax.annotation.Resource;
import org.apache.http.HttpStatus;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.dingding.common.core.base.dto.AbstractResponse;
import com.dingding.common.core.base.dto.ResponseEntity;
import com.dingding.common.core.beans.City;
import com.dingding.order.core.servicemod.biz.IServiceModuleService;
import com.dingding.order.core.servicemod.dao.ICityDao;
import com.dingding.order.core.servicemod.sql.ServiceModuleSql;
import com.dingding.order.dto.servicemod.GetServiceCitiesDto;
import com.dingding.order.dto.servicemod.ResGetServiceCities;

@Component("serviceModuleService")
public class ServiceModuleServiceImpl extends AbstractResponse<ResGetServiceCities, ResGetServiceCities> implements IServiceModuleService {

	private Logger log = Logger.getLogger(this.getClass());
	
	@Resource(name = "cityDao")
	private ICityDao cityDao;
	
	/**
	 * @Description:获取服务城市列表
	 * @author fengshuonan
	 * @since 2.4
	 */
	@SuppressWarnings("unchecked")
	@Override
	@Transactional(readOnly = true)
	public String getServiceCities(String clientData) {
		ResponseEntity<ResGetServiceCities> response = new ResponseEntity<ResGetServiceCities>();
		ResGetServiceCities resGetServiceCities = new ResGetServiceCities();
		
		List<GetServiceCitiesDto> list = null;
		List<String> fields = new ArrayList<String>();
		fields.add("cityNo");
		fields.add("cityName");
		
		try {
			list = (List<GetServiceCitiesDto>) this.cityDao.listSqlToCustomBean(ServiceModuleSql.GET_SERVICE_MODEL_LIST, 0, 0, GetServiceCitiesDto.class, fields);
		} catch (Exception e) {
			response.setCode(HttpStatus.SC_INTERNAL_SERVER_ERROR);
			response.setErrorMessage("网络异常");
			response.setPromptMessage("网络异常");
			log.error("获取所有城市列表出错！ServiceModuleServiceImpl:getServiceCities()",e);
			return super.responseBeanToJson(response);
		}
		
		if(list != null){
			resGetServiceCities.setCityList(list);
			response.setCode(HttpStatus.SC_OK);
			response.setErrorMessage("请求成功");
			response.setPromptMessage("请求成功");
			response.setResponseBody(resGetServiceCities);
			return super.responseBeanToJson(response);
		}else{
			response.setCode(HttpStatus.SC_OK);
			response.setErrorMessage("没有服务城市");
			response.setPromptMessage("没有服务城市");
			return super.responseBeanToJson(response);
		}
	}
}
